{% extends "main/base.html" %}
{% load i18n static main_tag %}
{% block title %}{% trans '订单列表' %}{% endblock %}
{% block this_css %}
<link rel="stylesheet" type="text/css" href="{% static 'flatlab/css/bootstrap-select.min.css' %}">
{% endblock %}
{% block content %}
<section class="panel">
    <div class="panel-body">
        <div class="col-md-11">
            <form class="form-inline" role="form" method="get">
                {% if order_states %}<div class="form-group">
                    <select name="c" class="selectpicker show-tick form-control" data-live-search="true">
                        <option value="">{% trans '所有订单' %}</option>
                        {% for ss in order_states %}
                            {% if ss.pk|floatformat:'0' == request.GET.c|floatformat:'0' %}
                            <option value="{{ ss.pk }}" selected>{{ ss }}</option>
                            {% else %}
                            <option value="{{ ss.pk }}" >{{ ss }}</option>
                            {% endif %}
                        {% endfor %}
                    </select>
                </div>{% endif %}
                {% if sub_companies %}<div class="form-group">
                    <select name="f" class="selectpicker show-tick form-control" data-live-search="true">
                        <option value="">{% trans '所有公司' %}</option>
                        {% for ss in sub_companies %}
                            {% if ss.pk|floatformat:'0' == request.GET.f|floatformat:'0' %}
                            <option value="{{ ss.pk }}" selected>{{ ss }}</option>
                            {% else %}
                            <option value="{{ ss.pk }}" >{{ ss }}</option>
                            {% endif %}
                        {% endfor %}
                    </select>
                </div>{% endif %}{% if perms.main.view_all_orders %}
                {% if created_bys %}<div class="form-group">
                    <select name="d" class="selectpicker show-tick form-control" data-live-search="true">
                        <option value="">{% trans '创建者' %}</option>
                        {% for ss in created_bys %}
                            {% if ss.pk|floatformat:'0' == request.GET.d|floatformat:'0' %}
                            <option value="{{ ss.pk }}" selected>{{ ss }}</option>
                            {% else %}
                            <option value="{{ ss.pk }}" >{{ ss }}</option>
                            {% endif %}
                        {% endfor %}
                    </select>
                </div>{% endif %}{% endif %}
                <div class="form-group">
                    <div class="input-group">
                        <span class="input-group-addon">{% trans '起始' %}:</span>
                        <input type="date" name="s" class="form-control" value="{% if request.GET.s %}{{ request.GET.s }}{% endif %}">
                    </div>
                </div>
                <div class="form-group">
                    <div class="input-group">
                        <span class="input-group-addon">{% trans '截止' %}:</span>
                        <input type="date" name="e" class="form-control" value="{% if request.GET.e %}{{ request.GET.e }}{% endif %}">
                    </div>
                </div>
                <div class="form-group">
                    <div class="input-group">
                        <input class="form-control" type="text" name="q" placeholder="" value="{% if request.GET.q %}{{ request.GET.q }}{% endif %}">
                        <span class="input-group-btn"><button class="btn btn-primary" type="submit">搜索</button></span>
                    </div>
                </div>{% if order_states %}
                <div class="form-group">
                    <div class="input-group">
                        <a href="{% url 'main:order_list' %}?c=1&d={{ request.user.pk }}"><button type="button" class="btn btn-warning"><i class="fa fa-exclamation-triangle"></i></button></a>
                    </div>
                </div>{% endif %}
            </form>
        </div>
        <div class="col-md-1" align="right">{% if perms.main.add_order %}
            <a href="{% url 'main:order_create' %}?next={{ request.path }}"><button type="button" class="btn btn-success">{% trans "创建订单" %}</button></a>{% endif %}
        </div>
    </div>
</section>
<section class="panel">
    {% get_current_language as LANGUAGE_CODE %}
    <div class="table-responsive panel-body">
        <table class="table table-striped">
            <thead>
                <tr>
                    <th>{% trans 'No.' %}</th>
                    <th>{% trans '编号/状态' %}</th>
                    <th>{% trans '订单描述' %}</th>
                    <th>{% trans '创建于' %}/{% trans '有效期' %}</th>{% if perms.main.view_equipment_basic_price %}
                    <th>{% trans '订单总价' %}</th>{% endif %}{% if perms.main.view_contract %}
                    <th>{% trans '合同/报价单' %}</th>{% endif %}
                    <th>{% trans '附件' %}</th>
                    <th>{% trans '客户' %}</th>
                    <th>{% trans '销售' %}</th>
                </tr>
            </thead>
            <tbody>
            {% for d in page_obj %}
                <tr>
                    <td>{{ d.id }}</td>
                    <th>{% if perms.main.view_order %}<a href="{% url 'main:order_detail' d.id %}">{{ d.order_code }}</a>{% else %}{{ d.order_code }}{% endif %}<br>{{ d.order_state }}</th>
                    <td>{{ d.order_desc }}</td>
                    <td>{{ d.order_create_date|date:"Y-m-d" }}<br>{{ d.order_validity_date|date:"Y-m-d" }}</td>{% if perms.main.view_equipment_basic_price %}
                    <td>¥ {{ d.price_all_final|default_if_none:'N/A' }}</td>{% endif %}
                    <td>
                        {% if perms.main.view_contract %}
                        {% if d.order_file %}<a href="{{ d.order_file|qiniu }}" target="_blank">{{ d.order_file.name|short }}</a><br>{% endif %}
                        {% if d.order_file_c %}<a href="{{ d.order_file_c|qiniu }}" target="_blank">{{ d.order_file_c.name|short }}</a>{% endif %}
                        {% endif %}
                    </td>
                    <td></td>
                    <td>{{ d.client.name }}</td>
                    <td>{{ d.salesman.name }}</td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
        <div align="right">
            {% include 'main/tablenav.html' %}
        </div>
    </div>
</section>
{% endblock %}
{% block this_js %}
<script type="text/javascript" src="{% static 'flatlab/js/bootstrap-select.min.js' %}"></script>
{% endblock %}